Description:
Compound assignment operators (*=, /=, %=, +=, -=, <<=, >>=,
&=, ^=, and |=) should be used where possible.
If they are not used, a warning message is generated.
Incorrect:
int numBits(int val) {
int count = 0;
while (val != 0) {
count = count + (val & 1);
val = val / 2;
}
return count;
}
Correct:
int numBits(int val) {
int count = 0;
while (val != 0) {
count += val & 1;
val /= 2;
}
return count;
}